<template>
	<view class="edit">
		<u-field v-model="dataForm.bank" label="收款银行" required disabled input-align='right'>
		</u-field>
		<u-field v-model="dataForm.bank_account" label="银行账号" required disabled input-align='right'>
		</u-field>
		<u-field v-model="dataForm.payee" label="收款人" required disabled input-align='right'>
		</u-field>
		<u-field v-model="dataForm.total_amount" label-width='150' label="可提现金额" disabled input-align='right'>
		</u-field>
		<u-field v-model="dataForm.amount" required label="提现金额" disabled placeholder="未获取到金额" input-align='right'>
		</u-field>
		<u-field v-model="dataForm.remark" label="提现备注" placeholder="非必填,可填写提现要求" type='textarea' input-align='right'
			:clearable='false'>
		</u-field>
		<view class="tip">
			<view class="">温馨提示：</view>
			<view class="">1、提现默认使用微信零钱转账，每天每笔最大限额支付为5000元</view>
			<view class="">2、银行帐号在个人我的信息编辑添加</view>
			<view class="">3、可提现金额=平台采购*数量</view>
		</view>
		<view class="btn" @click="submit">提交审核</view>
	</view>
</template>

<script>
	import {
		adminPost
	} from '@/common/http.request.js'
	export default {
		data() {
			return {
				dataForm: {
					amount: '',
					bank: '',
					bank_account: '',
					payee: '',
					total_amount: '',
					remark: ''
				},
				judeg:true
			}
		},
		onLoad(options) {
			this.initPage(options)
		},
		methods: {
			initPage(options) {
				this.$loading()
				this.$adminPost('adminGetProductSupplierInfo', {
					pk_id: this.vuex_adminuser.supplier_id,
					type:6
				}).then(res => {
				
					this.dataForm.bank = res.data.bank
					this.dataForm.bank_account = res.data.bank_account
					this.dataForm.payee = res.data.payee
					this.dataForm.total_amount = (res.data.total_amount - res.data.amount).toFixed(2)
					this.dataForm = {
						...this.dataForm,
						...JSON.parse(options.params),
						amount:JSON.parse(options.params).amount.toFixed(2),
						business_id:this.vuex_business.pk_id
					}
					this.$hide()
				})
			},
			submit() {
				if(!this.judeg)return
				this.$loading()
				let {
					bank,
					bank_account,
					payee,
					amount,
					total_amount
				} = this.dataForm
				
				if (!bank || !bank_account || !payee) {
					return this.$toast('请到店铺信息补全资料')
				} else if (!amount) {
					return this.$toast('提现金额不能为空')
				} else if (Number(amount) > 5000) {
					return this.$toast('提现金额不能超过5000')
				} else if (Number(amount) > Number(total_amount)) {
					return this.$toast('可提现金额不足')
				}
				this.dataForm.type = 6
				this.dataForm.business_id = this.vuex_business.pk_id
				this.dataForm.fk_supplier_id = this.vuex_adminuser.supplier_id
				delete this.dataForm.total_amount
				adminPost('AddSupplierWithdraw', {
					...this.dataForm
				}).then(res => {
					this.$hide()
					this.judeg = false
					this.$toast('提交成功')
					setTimeout(() => {
						this.uniBack(1)
					}, 1000)
				}).catch(() => {
					this.$hide()
					this.$toast('提交失败')
				})



			}
		}
	}
</script>

<style lang="scss" scoped>
	.edit {
		padding: 0 26rpx;

		.tip {
			padding-top: 60rpx;
			width: 100%;
			color: #999;
			font-size: 22rpx;
			height: 200rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
		}

		.btn {
			position: fixed;
			bottom: env(safe-area-inset-bottom);
			width: 698rpx;
			color: #fff;
			background-color: #2d8cf0;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 10rpx;
			height: 80rpx;
		}
	}
</style>
